﻿using System;
using System.Diagnostics;
using System.Threading;
//
using Ombc.Core;
using Ombc.Core.Interfaces;

namespace SendMessageConsoleExample
{
	class Program
	{
		static void Main(string[] args)
		{
			Trace.WriteLine("- Creating Azure SB Service 2.4 client instance.");
			IOmbcClient client = new OmbcClient(OmbcClientType.AzureServiceBusService24);

			client.Initialize(o =>
			{
				o.Namespace = "ombctest";
				o.ManagementPort = "-1";
				o.MessagingPort = "-1";
				o.UserId = "owner";
				o.Password = "dzoXeRnbz5vLGz5zkLnau9eHw3wCvXF8LZNnY6012YA=";
				o.OperationTimeout = TimeSpan.FromSeconds(10).ToString();
			});


			// Adam: No need to subscribe in this application only need to Publish as commented below.
			client.Subscribe<TestMessage>("TestSubscription",
				m =>
				{
					Trace.WriteLine(string.Format("Received TestMessage with Text [{0}].", m.Text));
					Console.WriteLine(string.Format("Received TestMessage with Text [{0}].", m.Text));
				});

			for (int i = 1; i <= 2; i++)
			{
				Thread.Sleep(1000);

				// Adam: To send message simple create a message instance and publish it as in these 2 lines of code.
				var msg = new TestMessage { Text = string.Format("({0}) Hello OMBC. {1}.", i, DateTime.Now.ToString("HH:mm:ss.fff")) };
				client.Publish(msg);
			}

			Thread.Sleep(3000);
			client.Dispose();

			Console.Write("Press <Enter> to stop: ");
			Console.ReadLine();
		}
	}
}
